//
//  PTTabBarVC.m
//  platformDemo
//
//  Created by Owen on 2020/6/9.
//  Copyright © 2020 Owen. All rights reserved.
//

#import "PTTabBarVC.h"
#import "PTTabBarView.h"

@interface PTTabBarVC ()<UITabBarControllerDelegate,PTTabBarViewDelegate>

@property (nonatomic,strong) UIViewController *currentVC;


//自定义tabBar
@property (nonatomic,strong) PTTabBarView *tabBarView;


@end

@implementation PTTabBarVC

- (instancetype)init{
    
    self = [super init];
    
    if (self) {
        
        //自定义tabBar

        
    }
    
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.view.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:self.tabBarView];
    [self setTabBarControllers];
    
    
}

- (void)viewWillAppear:(BOOL)animated{
    
    [super viewWillAppear:animated];
    
    self.tabBarView.frame = CGRectMake(0,
                                       HEIGHT - UITabBarHeight - SafeAreaBottomHeight,
                                       WIDTH,
                                       UITabBarHeight + SafeAreaBottomHeight);
}

- (void)setTabBarControllers {
    
    self.homeVC = [[PTHomeVC alloc] init];
    self.liveVC = [[PTLiveVC alloc] init];
    self.personalCenterVC = [[PTPersonalCenterVC alloc] init];
    
    self.viewControllers = @[self.homeVC,
                             self.liveVC,
                             self.personalCenterVC];
    self.tabBar.hidden = YES;
    
}

- (PTTabBarView *)tabBarView{
    
    if (_tabBarView == nil) {
        
        _tabBarView = [[PTTabBarView alloc] init];
        _tabBarView.delegate = self;
        _tabBarView.backgroundColor = [UIColor whiteColor];

    }
    
    return _tabBarView;
}



/// 显示某个控制器
/// @param tag 控制器类型
- (void) showCurrentViewController:(TabBarTag) tag{
    
    switch (tag) {
        case HomeTag:
            self.selectedViewController = self.viewControllers[0];
            self.currentVC = self.viewControllers[0];
            self.selectedIndex = 0;
            
            break;
        case LiveTag:
            self.selectedViewController = self.viewControllers[1];
            self.currentVC = self.viewControllers[1];
            self.selectedIndex = 1;
            
            break;
        case PersonalCenterTag:
            self.selectedViewController = self.viewControllers[2];
            self.currentVC = self.viewControllers[2];
            self.selectedIndex = 2;
            break;
            
        default:
            break;
    }
    
}

- (void) hiddenTabBarView{
    
//    self.tabBar.hidden = YES;
}

- (void) showTabBarView{
    
    
//    self.tabBar.hidden = NO;
}

#pragma mark - PTTabBarViewDelegate


/// 控制器切换
/// @param index 标示tag
- (void) touchSelectIndex:(int) index{
    
    self.selectedViewController = self.viewControllers[index - 1];
    self.currentVC = self.viewControllers[index - 1];
    self.selectedIndex = index - 1;
}
@end
